<?php

namespace app\admin\controller;

use app\admin\model\SignSetModel;
use cmf\controller\AdminBaseController;
use think\Request;

class SignSetController extends AdminBaseController
{

    /**
     * 显示创建资源表单页.
     *
     * @return \think\Response
     */
    public function add()
    {
        $rule = SignSetModel::all();
        $this->assign('rule',$rule);

        return $this->fetch();
    }

    /**
     * 保存新建的资源
     *
     * @param  \think\Request  $request
     * @return \think\Response
     */
    public function save(Request $request,SignSetModel $model)
    {
        $data = $request->param();

        for ($i=1;$i<=count($data['get_coin']);$i++){

            $rule = ['day' => $i ,'get_coin' => $data['get_coin'][$i-1]];
            $model->allowField(true)->create($rule);
        }

        $this->success('添加成功!');
    }



    /**
     * 保存更新的资源
     *
     * @param  \think\Request  $request
     * @param  int  $id
     * @return \think\Response
     */
    public function update(Request $request,SignSetModel $model)
    {
        $data = $request->param();
        for ($i=0;$i<count($data['get_coin']);$i++){

            $rule = ['get_coin' => $data['get_coin'][$i]];
            $model->allowField(true)->update($rule,['id'=>$data['id'][$i]]);
        }
        $this->success('保存成功!');
    }


}
